//
//  MBBottomView.m
//  MiBaoTu
//
//  Created by 彭鹏 on 16/10/6.
//  Copyright © 2016年 com.caesartech15. All rights reserved.
//

#import "MBBottomView.h"
@interface MBBottomView ()
{
    
    UIView                      *_userView;
    UIImageView                 *_userImgView;
    UILabel                     *_nickNameLb;
    UILabel                     *_userDetailLb;
    UILabel                     *_downingLb;
    UILabel                     *_downedLb;
    UILabel                     *_usedLb;
}

@end
@implementation MBBottomView


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
            [self creatUI];
    }
    return self;
}
-(void)creatUI{
    self.backgroundColor = [UIColor clearColor];
    
    UIView *bottomView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)];
    bottomView.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:30];
    if (ISIPAD) {
        bottomView.frame=CGRectMake(0, 0, self.width, 120*PERCEN);
        bottomView.backgroundColor=[UIColorFromHex(0xffffff) colorWithAlphaComponent:.4];
    }
    
    [self addSubview:bottomView];
    
    float itemWidth = bottomView.width / 4.;
    
    for (int i = 0; i<4;i++ ) {
        if (i==0) {
            self.praiseBtn=[UIButton buttonWithType:UIButtonTypeCustom];
            self.praiseBtn.frame=CGRectMake(itemWidth*i, 0, itemWidth, bottomView.height);
            self.praiseBtn.titleLabel.font=[UIFont systemFontOfSize:22*PERCEN];
            [self.praiseBtn setTitleColor:UIColorFromHex(0xffffff) forState:0];
//            if (_isParise) {
//                 [self.praiseBtn setImage:[UIImage imageNamed:@"zan2_qzxbf"] forState:0];
//            }
//            else{
            [self.praiseBtn setImage:[UIImage imageNamed:@"zan_qzxbf"] forState:0];
//            }
           
            if (ISIPAD) {
                self.praiseBtn.imageEdgeInsets=UIEdgeInsetsMake(-20,50, 0, 0);
                self.praiseBtn.titleEdgeInsets=UIEdgeInsetsMake(30, 0, 0, 0);

            }else{


                if (WIDTH_5S) {
                    self.praiseBtn.imageEdgeInsets=UIEdgeInsetsMake(-20,32, 0, 0);
                    self.praiseBtn.titleEdgeInsets=UIEdgeInsetsMake(20, 0, 0, 10);
                }else {
                self.praiseBtn.imageEdgeInsets=UIEdgeInsetsMake(-20,40, 0, 0);

                self.praiseBtn.titleEdgeInsets=UIEdgeInsetsMake(20, 0, 0, 10);
              }
            }
                      [bottomView addSubview:self.praiseBtn];
              [self.praiseBtn addTarget:self action:@selector(onSelectPraiseAction) forControlEvents:UIControlEventTouchUpInside];
        }
        else if (i==1){
            self.collectBtn=[UIButton buttonWithType:UIButtonTypeCustom];
            self.collectBtn.frame=CGRectMake(itemWidth*i, 0, itemWidth, bottomView.height);
            self.collectBtn.titleLabel.font=[UIFont systemFontOfSize:22*PERCEN];
            [self.collectBtn setTitleColor:UIColorFromHex(0xffffff) forState:0];
//            if (_isCollect) {
//                [self.collectBtn setImage:[UIImage imageNamed:@"shoucang2_qzxbf"] forState:0];
//            }else{
            [self.collectBtn setImage:[UIImage imageNamed:@"shoucang_qzxbf"] forState:0];
//            }
            if (ISIPAD) {
                self.collectBtn.imageEdgeInsets=UIEdgeInsetsMake(-20,50, 0, 0);
                self.collectBtn.titleEdgeInsets=UIEdgeInsetsMake(30, 0, 0, 0);
                
            }else{

                if (WIDTH_5S) {
                    self.collectBtn.imageEdgeInsets=UIEdgeInsetsMake(-20,32, 0, 0);
                    self.collectBtn.titleEdgeInsets=UIEdgeInsetsMake(20, 0, 0, 10);
                }else {
                    self.collectBtn.imageEdgeInsets=UIEdgeInsetsMake(-20,40, 0, 0);
                    self.collectBtn.titleEdgeInsets=UIEdgeInsetsMake(20, 0, 0, 10);
                }

            }
            [bottomView addSubview:self.collectBtn];
               [self.collectBtn addTarget:self action:@selector(onSelectShouCangAction) forControlEvents:UIControlEventTouchUpInside];
        }
        else if (i==2)
        {
            self.commentBtn=[UIButton buttonWithType:UIButtonTypeCustom];
            self.commentBtn.frame=CGRectMake(itemWidth*i, 0, itemWidth, bottomView.height);
            self.commentBtn.titleLabel.font=[UIFont systemFontOfSize:22*PERCEN];
            [self.commentBtn setTitleColor:UIColorFromHex(0xffffff) forState:0];
            [self.commentBtn setImage:[UIImage imageNamed:@"pinglun_qzxbf"] forState:0];
            if (ISIPAD) {
                self.commentBtn.imageEdgeInsets=UIEdgeInsetsMake(-20,50, 0, 0);
                self.commentBtn.titleEdgeInsets=UIEdgeInsetsMake(30, 0, 0, 0);
                
            }else{

                if (WIDTH_5S) {
                    self.commentBtn.imageEdgeInsets=UIEdgeInsetsMake(-20,32, 0, 0);
                    self.commentBtn.titleEdgeInsets=UIEdgeInsetsMake(20, 0, 0, 10);
                }else {
                    self.commentBtn.imageEdgeInsets=UIEdgeInsetsMake(-20,40, 0, 0);
                    self.commentBtn.titleEdgeInsets=UIEdgeInsetsMake(20, 0, 0, 10);
                }

            }
            [bottomView addSubview:self.commentBtn];

            
            [self.commentBtn addTarget:self action:@selector(onSelectCommentAction) forControlEvents:UIControlEventTouchUpInside];
        }else{
            self.shareBtn=[UIButton buttonWithType:UIButtonTypeCustom];
            self.shareBtn.frame=CGRectMake(itemWidth*i, 0, itemWidth, bottomView.height);
            self.shareBtn.titleLabel.font=[UIFont systemFontOfSize:22*PERCEN];
            [self.shareBtn setTitleColor:UIColorFromHex(0xffffff) forState:0];
            [self.shareBtn setImage:[UIImage imageNamed:@"fenxiang_qzxbf"] forState:0];
            if (ISIPAD) {
                self.shareBtn.imageEdgeInsets=UIEdgeInsetsMake(-20,50, 0, 0);
                self.shareBtn.titleEdgeInsets=UIEdgeInsetsMake(30, 0, 0, 0);
                
            }else{
                if (WIDTH_5S) {
                    self.shareBtn.imageEdgeInsets=UIEdgeInsetsMake(-20,32, 0, 0);
                    self.shareBtn.titleEdgeInsets=UIEdgeInsetsMake(20, 0, 0, 10);
                }else {
                    self.shareBtn.imageEdgeInsets=UIEdgeInsetsMake(-20,40, 0, 0);
                    self.shareBtn.titleEdgeInsets=UIEdgeInsetsMake(20, 0, 0, 10);
                }

            }

            [bottomView addSubview:self.shareBtn];
            [self.shareBtn addTarget:self action:@selector(onSelectShareAction) forControlEvents:UIControlEventTouchUpInside];
        }
    }
}


- (void)setIsParise:(BOOL)isParise
{
    
    _isParise = isParise;
    if (_isParise) {
        [self.praiseBtn setImage:[UIImage imageNamed:@"zan2_qzxbf"] forState:0];
       [_praiseBtn setTitleColor:TINK_COLOR forState:0];
    }
    else{
        [self.praiseBtn setImage:[UIImage imageNamed:@"zan_qzxbf"] forState:0];
        [_praiseBtn setTitleColor:[UIColor whiteColor] forState:0];
    }
}

- (void)setDataDic:(NSDictionary *)dataDic
{
    if (!_dataDic) {
        _dataDic = [[NSDictionary alloc]init];
    }
    _dataDic = dataDic;

    NSString *pStr = [_dataDic objectForKey:@"PraiseNum"];
    if ([pStr isKindOfClass:[NSNull class]]) {
        pStr = @"0";
    }
    NSString *praiseStr = [NSString stringWithFormat:@"点赞(%@)",pStr];
    NSString *cStr = [_dataDic objectForKey:@"CollectNum"];
    if ([cStr isKindOfClass:[NSNull class]]) {
        cStr = @"0";
    }
    NSString *collecionStr = [NSString stringWithFormat:@"收藏(%@)",cStr];
    

    NSString*CollectStatus=[NSString stringWithFormat:@"%@",dataDic[@"CollectStatus"]];//收藏状态
     NSString*PraiseStatus=[NSString stringWithFormat:@"%@",dataDic[@"PraiseStatus"]];//点赞状态


    
    if ([PraiseStatus isEqualToString:@"1"]) {
         [self.praiseBtn setImage:[UIImage imageNamed:@"zan2_qzxbf"] forState:0];
          [_praiseBtn setTitleColor:TINK_COLOR forState:0];
    }else{
            [self.praiseBtn setImage:[UIImage imageNamed:@"zan_qzxbf"] forState:0];
         [_praiseBtn setTitleColor:[UIColor whiteColor] forState:0];
    }
    
    if ([CollectStatus isEqualToString:@"1"]) {
        [_collectBtn setImage:[UIImage imageNamed:@"shoucang2_qzxbf"] forState:0];
        [_collectBtn setTitleColor:TINK_COLOR forState:0];
    }else{
        [_collectBtn setImage:[UIImage imageNamed:@"shoucang_qzxbf"] forState:0];
        [_collectBtn setTitleColor:[UIColor whiteColor] forState:0];

    }

//    NSString *ShareNum = [NSString stringWithFormat:@"分享(%@)",[_dataDic objectForKey:@"ShareNum"]];
    [_praiseBtn setTitle:praiseStr forState:0];
    [_collectBtn setTitle:collecionStr forState:0];
//    [_shareBtn setTitle:ShareNum forState:0];

}

- (void)onChangePraiseDate:(BOOL)isPrase
{
    NSString *str = _praiseBtn.titleLabel.text;
    if (str.length == 0) return;
    
    str = [str substringWithRange:NSMakeRange(3, str.length-4)];
    NSString *praiseStr;
    if (isPrase) {
       [self.praiseBtn setImage:[UIImage imageNamed:@"zan2_qzxbf"] forState:0];
        praiseStr = [NSString stringWithFormat:@"点赞(%d)",[str intValue]+1];
        [_praiseBtn setTitleColor:TINK_COLOR forState:0];
    } else {
        [self.praiseBtn setImage:[UIImage imageNamed:@"zan_qzxbf"] forState:0];
        praiseStr = [NSString stringWithFormat:@"点赞(%d)",[str intValue]-1];
        [_praiseBtn setTitleColor:[UIColor whiteColor] forState:0];
    }
    [_praiseBtn setTitle:praiseStr forState:0];
}

- (void)setIsCollect:(BOOL)isCollect
{
    _isCollect = isCollect;
     NSString *str = _collectBtn.titleLabel.text;
    str = [str substringWithRange:NSMakeRange(3, str.length-4)];
     NSString *praiseStr;
    if (_isCollect) {
        [_collectBtn setImage:[UIImage imageNamed:@"shoucang2_qzxbf"] forState:0];
         praiseStr = [NSString stringWithFormat:@"点赞(%d)",[str intValue]+1];
        [_collectBtn setTitleColor:TINK_COLOR forState:0];

    }
    else{
        [_collectBtn setImage:[UIImage imageNamed:@"shoucang_qzxbf"] forState:0];
         praiseStr = [NSString stringWithFormat:@"点赞(%d)",[str intValue]-1];
        [_collectBtn setTitleColor:[UIColor whiteColor] forState:0];
    }
}

- (void)onChangeCollectionDate:(BOOL)isCollection
{
    NSString *str = _collectBtn.titleLabel.text;
    if (str.length == 0) return;
    
    str = [str substringWithRange:NSMakeRange(3, str.length-4)];
 
    NSString *praiseStr;
    if (isCollection) {
        [_collectBtn setImage:[UIImage imageNamed:@"shoucang2_qzxbf"] forState:0];
        praiseStr = [NSString stringWithFormat:@"收藏(%d)",[str intValue]+1];
        [_collectBtn setTitleColor:TINK_COLOR forState:0];
    } else {
        [_collectBtn setImage:[UIImage imageNamed:@"shoucang_qzxbf"] forState:0];
        praiseStr = [NSString stringWithFormat:@"收藏(%d)",[str intValue]-1];
        [_collectBtn setTitleColor:[UIColor whiteColor] forState:0];
    }
    [_collectBtn setTitle:praiseStr forState:0];
  
}

- (void)setShareNum:(NSString *)shareNum
{
    _shareNum = [NSString stringWithFormat:@"分享(%@)",shareNum];
    [_shareBtn setTitle:_shareNum forState:0];
}

- (void)setCommentNum:(NSString *)commentNum
{
    _commentNum = [NSString stringWithFormat:@"评论(%@)",commentNum];
    [_commentBtn setTitle:_commentNum forState:0];
}

//点赞
- (void)onSelectPraiseAction {
    NSLog(@"点赞");
    if (_delegate && [_delegate respondsToSelector:@selector( onSelectItemPraiseWithView:withValue:)])
        [_delegate onSelectItemPraiseWithView:self withValue:_dataDic];
}
//收藏
- (void)onSelectShouCangAction
{ NSLog(@"收藏");
    if (_delegate && [_delegate respondsToSelector:@selector(onselectItemForShouCangWithView: withValue:)]) {
        [_delegate onselectItemForShouCangWithView:self withValue:_dataDic];
    }
}

//评论
- (void)onSelectCommentAction {
    
        if (_delegate && [_delegate respondsToSelector:@selector( onSelectITemForCommentWithView:)]) {
            [_delegate onSelectITemForCommentWithView:self];
        }}

//分享
- (void)onSelectShareAction
{
    
    if (_delegate && [_delegate respondsToSelector:@selector(onSelectITemForShareWithView:withValue:)]) {
        [_delegate onSelectITemForShareWithView:self withValue:_dataDic];
    }
}


- (void)setText:(BOOL)text
{
    _text = text;
    [self setNeedsLayout];
}
//
//- (void)layoutSubviews
//{
//    [super layoutSubviews];
//    
//    _userImgView.image = [UIImage imageNamed:@"baba_zl"];
//    _nickNameLb.text = @"米宝宝";
//    _userDetailLb.text = @"宝宝爱吃爱喝爱睡觉，不服你来比一比！哼哼。";
//    _downingLb.text = @"7首";
//    _downedLb.text = @"13首";
//    _usedLb.text = @"33首";
//}

@end

